﻿using System;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace UpdaterForm
{
    //tut naverno singleton nado sdelat
    [XmlRoot("Configuration", Namespace = "", IsNullable = false)]
    public class Configuration
    {
        private String _repositoryPath;

        [XmlElement("RepositoryPath")]
        public String RepositoryPath
        {
            get
            {
                if (String.IsNullOrEmpty(_repositoryPath))
                {
                    _repositoryPath = SelectFolder();
                }
                return _repositoryPath;
            }
            set { _repositoryPath = value; }
        }

        [XmlElement("Applications")]
        public Data Data { get; set; }

        [XmlElement("DateFormat")]
        public String DateFormat { get; set; }

        [XmlElement("MessageFileName")]
        public String MessageFileName { get; set; }

        private string SelectFolder()
        {
            var dialog = new FolderBrowserDialog();
            dialog.Description = "Please select repository folder.";
            DialogResult result = dialog.ShowDialog();
            if (result != DialogResult.OK)
                return "";
            return dialog.SelectedPath;
        }
    }
}